-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternate solution to command api. #446
Conversation
d69e265
to
c0cfc83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly skimmed through it for now but it's looking good so far. Let me know when you're ready for another review.
# Conflicts: # Cargo.toml # crates/valence_server/Cargo.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that's missing is error handling for commands that failed to parse. If someone types /gamemode aklwjdlkawlhd
, How do I tell them Unknown game mode: aklwjdlkawlhd
?
I also noticed that in vanilla, It's because the gamemode parser isn't being used in this example./gamemode aklwjdlkawlhd
will give me the "unknown game mode" message while the command is still being typed. What packet is responsible for that, and how do we do that ourselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is up to whomever handles raw strings to send warnings (the client will show red text with the current parsing). Trying to guess what node a client is talking about with a broken or incomplete command is a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But how do I get access to the error that occurred so I can send an error in the chat or whatever else? It looks like the error is thrown away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is when trying to match a node an error is assumed to mean that the command doesn't match the given node. For example if we have two executables at /foo and one is a number arg and the other is a string arg /foo bar should not trigger "expected number got bar".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at the source for GameModeArgumentType
and it throws an exception when the gamemode fails to parse.
private static final DynamicCommandExceptionType INVALID_GAME_MODE_EXCEPTION = new DynamicCommandExceptionType(gameMode -> Text.translatable("argument.gamemode.invalid", gameMode));
argument.gamemode.invalid
translates to the message the user sees when they type /gamemode aklwjdlkawlhd
.
So clearly the error is bubbling up somehow, but I don't know what the semantics are exactly. Might need to dig into the brigadier source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would have to make some assumptions 1. no other nodes match 2. no better fit for error reporting. This applies fine to the small set of uncomplicated vinnila commands but anything more complex and dynamic will cause headaches in the future. OTOH We could label exclusive args somehow (the only arg reachable at a certain path) and bubble those errors up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe vanilla is throwing away all but the last exception? Just a guess, but I'd like to get a confirmation so we can have more confidence in a decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we hash args based on the path taken to get to them and if the hash is unique then we report errors when the arg does not match. This only solves the problem for unique beaches (most cases). This would not be too hard to implement, I can probably do it in about 30m to an hour tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what is brigadier doing to resolve this situation? I doubt it's anything like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not read brigadier's code and I am not well versed on java so I don't particularly want to track it down.
examples/command.rs
Outdated
#[derive(Command, Debug, Clone)] | ||
#[paths("gamemode", "gm")] | ||
#[scopes("valence.command.gamemode")] | ||
enum Gamemode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is the best command to use as an example because people like me will be wondering why we're not just using the normal GameMode
parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how the current version shows multiple paths or redirections. we could add a comment if we must.
# Conflicts: # assets/depgraph.svg
Objective
I want to add commands ergonomically, unfortunately @Jenya705 's implementation did not look to promising for my purposes so I am working on an alternative command api.
Solution
lib-users should be able to make commands quickly and easily.
Some objectives in the order I plan to implement them:
Handle server-side suggestions.(this has been defered to the future)